import axios from 'axios';
import router from '../router/index';
const api = axios.create({
  baseURL:'https://api.it120.cc/small4',
  timeout: 5000
})

// 请求拦截，
api.interceptors.request.use(config => { 
  // console.log(router);
  if (!localStorage.getItem('token') && config.url == '/cms/news/list'){
    router.push('/login');
    return;
  }
  config.headers.token = localStorage.getItem('token');
  return config
},err => {
  return Promise.reject(err)
})

// 相应拦截
api.interceptors.response.use(res => {
  
  return Promise.resolve(res.data);
},err => {
    return Promise.reject(err)
})

export default api;